package com.functest.jpwise

import com.functest.jpwise.core.ParameterValue
import com.functest.jpwise.core.SimpleValue
import com.functest.jpwise.core.TestParameter
import com.functest.framework.BaseFunctionalTest
import com.functest.orm.ConditionOp
import org.testng.annotations.Test

import static com.functest.jpwise.ClosureBasedMatcher.valueWith

/**
 * @author: DavydovMD
 * Date: 20.06.13
 * Time: 11:36
 */
class ParamValueMatcherTest extends BaseFunctionalTest {

    @Test
    public void valueMatcherTest() {

        ParamValueMatcher matcher = valueWith { ParameterValue v -> v.name == 'Bob' }

        assert matcher.matches(SimpleValue.of('Bob'))
        assert matcher.matches(SimpleValue.of('Bob', 'Bobby'))
        assert !matcher.matches(SimpleValue.of('Бобр', 'Bobby'))

        matcher = new ConditionBasedMatcher(ConditionBasedMatcher.Field.Value, ConditionOp.EQ, String)

        assert matcher.matches(SimpleValue.of('Строчечка', String))
        assert matcher.matches(SimpleValue.of(String))
        assert !matcher.matches(SimpleValue.of('Цыфирь', Integer))


        TestParameter p1 = new TestParameter('param1', [SimpleValue.of('Value1'), SimpleValue.of('Value2')])
        TestParameter p2 = new TestParameter('param2', [SimpleValue.of('Value1'), SimpleValue.of('Value2')])
        ParameterValue val1
        val1 = p1.getValueByName('Value1');
        def val2 = p2.getValueByName('Value2');
        matcher = new ConditionBasedMatcher(ConditionBasedMatcher.Field.ParameterName, ConditionOp.NEQ, 'param1')
        assert matcher.matches(val2);
        assert !matcher.matches(val1);


        matcher = new ConditionBasedMatcher(ConditionBasedMatcher.Field.Value, ConditionOp.IN, ['Value1', 'Value2'], ConditionBasedMatcher.Field.ParameterName, ConditionOp.NOT_IN, ['param2'])
        assert matcher.matches(val1)
        assert !matcher.matches(val2)
        assert !matcher.matches(p2.getValueByIndex(0))
        assert !matcher.matches(p2.getValueByIndex(1))


    }


}
